self_organizing_map_utilities Module

This module defines a class for simple self_organizing_map (one kohonen layer)


Uses

  • module~~self_organizing_map_utilities~~UsesGraph module~self_organizing_map_utilities self_organizing_map_utilities error_handling error_handling module~self_organizing_map_utilities->error_handling module~constants_utilities constants_utilities module~self_organizing_map_utilities->module~constants_utilities module~distance_base_utilities distance_base_utilities module~self_organizing_map_utilities->module~distance_base_utilities module~factory_distance_utilities factory_distance_utilities module~self_organizing_map_utilities->module~factory_distance_utilities module~kohonen_layer_parameters_utilities kohonen_layer_parameters_utilities module~self_organizing_map_utilities->module~kohonen_layer_parameters_utilities module~kohonen_map_base_utilities kohonen_map_base_utilities module~self_organizing_map_utilities->module~kohonen_map_base_utilities module~kohonen_pattern_utilities kohonen_pattern_utilities module~self_organizing_map_utilities->module~kohonen_pattern_utilities module~kohonen_prototype_utilities kohonen_prototype_utilities module~self_organizing_map_utilities->module~kohonen_prototype_utilities module~precision_utilities precision_utilities module~self_organizing_map_utilities->module~precision_utilities module~quicksort_utilities quicksort_utilities module~self_organizing_map_utilities->module~quicksort_utilities module~random_generator_base_utilities random_generator_base_utilities module~self_organizing_map_utilities->module~random_generator_base_utilities module~rkiss05_generator_utilities rkiss05_generator_utilities module~self_organizing_map_utilities->module~rkiss05_generator_utilities module~constants_utilities->module~precision_utilities module~distance_base_utilities->module~precision_utilities module~factory_distance_utilities->error_handling module~factory_distance_utilities->module~constants_utilities module~factory_distance_utilities->module~distance_base_utilities module~correlation_distance_utilities correlation_distance_utilities module~factory_distance_utilities->module~correlation_distance_utilities module~direction_cosine_distance_utilities direction_cosine_distance_utilities module~factory_distance_utilities->module~direction_cosine_distance_utilities module~euclidean_distance_utilities euclidean_distance_utilities module~factory_distance_utilities->module~euclidean_distance_utilities module~manhattan_distance_utilities manhattan_distance_utilities module~factory_distance_utilities->module~manhattan_distance_utilities module~max_distance_utilities max_distance_utilities module~factory_distance_utilities->module~max_distance_utilities module~kohonen_layer_parameters_utilities->error_handling module~kohonen_layer_parameters_utilities->module~constants_utilities module~kohonen_layer_parameters_utilities->module~precision_utilities tomlf tomlf module~kohonen_layer_parameters_utilities->tomlf module~kohonen_map_base_utilities->module~kohonen_layer_parameters_utilities module~kohonen_map_base_utilities->module~kohonen_pattern_utilities module~kohonen_map_base_utilities->module~precision_utilities module~kohonen_pattern_utilities->error_handling module~kohonen_pattern_utilities->module~constants_utilities module~kohonen_pattern_utilities->module~kohonen_prototype_utilities module~kohonen_pattern_utilities->module~precision_utilities module~kohonen_prototype_utilities->error_handling module~kohonen_prototype_utilities->module~constants_utilities module~kohonen_prototype_utilities->module~distance_base_utilities module~kohonen_prototype_utilities->module~precision_utilities iso_fortran_env iso_fortran_env module~precision_utilities->iso_fortran_env module~quicksort_utilities->module~precision_utilities module~sort_base_utilities sort_base_utilities module~quicksort_utilities->module~sort_base_utilities module~random_generator_base_utilities->module~precision_utilities module~rkiss05_generator_utilities->module~precision_utilities module~rkiss05_generator_utilities->module~random_generator_base_utilities module~correlation_distance_utilities->module~distance_base_utilities module~correlation_distance_utilities->module~precision_utilities module~general_utilities general_utilities module~correlation_distance_utilities->module~general_utilities module~direction_cosine_distance_utilities->module~distance_base_utilities module~direction_cosine_distance_utilities->module~precision_utilities module~euclidean_distance_utilities->module~distance_base_utilities module~euclidean_distance_utilities->module~precision_utilities module~manhattan_distance_utilities->module~distance_base_utilities module~manhattan_distance_utilities->module~precision_utilities module~max_distance_utilities->module~distance_base_utilities module~max_distance_utilities->module~precision_utilities module~sort_base_utilities->module~precision_utilities module~general_utilities->module~precision_utilities

Used by

  • module~~self_organizing_map_utilities~~UsedByGraph module~self_organizing_map_utilities self_organizing_map_utilities module~som_predict_variables som_predict_variables module~som_predict_variables->module~self_organizing_map_utilities module~som_train_variables som_train_variables module~som_train_variables->module~self_organizing_map_utilities

Derived Types

type, public, extends(kohonen_map_base) ::  self_organizing_map

Class to represent a self_organizing_map

Type-Bound Procedures

procedure, public :: create => create_som
procedure, public :: destroy => destroy_som
procedure, public :: train => train_som_data
procedure, public :: predict => predict_som
procedure, public :: print => print_som
procedure, public :: read => read_som
procedure, public :: get_count => get_count_som
procedure, public :: query => query_som
procedure, public :: get_prototypes
procedure, public :: get_u_matrix => get_u_matrix_som
procedure, public, nopass :: external_train_map
procedure, public, nopass :: external_predict_map

Functions

public function position2index(ix, iy, iz, nx, ny) result(index_)

Function to calculate the index inside a rectangular grid from position ix,iy,iz

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ix

Integer variables

integer, intent(in) :: iy

Integer variables

integer, intent(in) :: iz

Integer variables

integer, intent(in) :: nx

Integer variables

integer, intent(in) :: ny

Integer variables

Return Value integer

Integer variable with the required index

public function calculate_sigma(kohonen_map, input_data, seed) result(sigma)

Function to calculate the scaling factor sigma

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

real(kind=wp), intent(inout), dimension(:,:) :: input_data

A real array with the input data

integer, intent(inout), optional :: seed

An integer with the random seed

Return Value real(kind=wp)

A real variable with the value of sigma


Subroutines

public subroutine create_som(kohonen_map, training_parameters)

Constructor for self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

type(kohonen_layer_parameters), dimension(:) :: training_parameters

A kohonen_layer_parameters object

public subroutine destroy_som(kohonen_map)

Destructor for self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

public subroutine create_random_sample(kohonen_map, input)

Subroutine to generate random values that serve as inputs to the SOM

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

real(kind=wp), intent(out), dimension(:,:) :: input

A real array with the initial values of the prototypes

public subroutine train_som_data(kohonen_map, input_data)

Training function for self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

type(kohonen_pattern), intent(inout), dimension(:) :: input_data

A kohonen_pattern array with the input data

public subroutine predict_som(kohonen_map, input_data, map_output)

Function for Prediction of a self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

type(kohonen_pattern), intent(inout), dimension(:) :: input_data

A kohonen_pattern array with the input data

integer, intent(out), dimension(:,:) :: map_output

An integer array with the map output

public subroutine print_som(kohonen_map, unit_)

Print function for self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map
integer, intent(inout), optional :: unit_

public subroutine get_count_som(kohonen_map, count_)

Function to get count matrix for self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map
integer, intent(inout), dimension(:,:,:) :: count_

public subroutine query_som(kohonen_map, input_pattern, sample_index)

Function to find the input samples associated with specific vector

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map
real(kind=wp), intent(inout), dimension(:,:) :: input_pattern
integer, allocatable :: sample_index(:)

public subroutine read_som(kohonen_map, som_fl)

Subroutine to read the prototypes to define a self_organizing_map

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

character(len=*) :: som_fl

A character variable with the name of the file

public subroutine index2position(index_, nx, ny, nz, cx, cy, cz)

Subroutine to calculate the position ix,iy,iz inside a rectangular grid from index

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: index_

Integer variable representing the index

integer, intent(in) :: nx

Integer variables representing the dimensions of the kohonen map

integer, intent(in) :: ny

Integer variables representing the dimensions of the kohonen map

integer, intent(in) :: nz

Integer variables representing the dimensions of the kohonen map

integer, intent(inout) :: cx

Integer variables representing the position of the node

integer, intent(inout) :: cy

Integer variables representing the position of the node

integer, intent(inout) :: cz

Integer variables representing the position of the node

public subroutine calculate_distance_matrix(coordinates, distance_matrix, grid_type, toroidal)

Subroutine to calculate the distance between the units inside a kohonen layer

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(inout), dimension(:,:) :: coordinates

Real array with the coordinates

real(kind=wp), intent(inout), dimension(:,:) :: distance_matrix

Real array with the distance_matrix

character(len=*) :: grid_type

Character variable with the grid type

logical :: toroidal

Logical variable for toroidal grid

public subroutine calculate_coordinates(current_index, ix, iy, iz, nx, ny, nz, coordinates, node_type)

Subroutine to calculate the coordinates of the units inside a kohonen layer

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: current_index
integer, intent(in) :: ix
integer, intent(in) :: iy
integer, intent(in) :: iz
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: nz
real(kind=wp), intent(out), dimension(:,:) :: coordinates
character(len=*), intent(in) :: node_type

public subroutine find_best_match_unit(kohonen_map, current_prototype, ihit, jhit, khit, dist_hit)

Subroutine to calculate the best match unit

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

type(kohonen_prototype), intent(inout) :: current_prototype

A kohonen_prototype object

integer, intent(out) :: ihit

Integer variables for the coordinates of the BMU

integer, intent(out) :: jhit

Integer variables for the coordinates of the BMU

integer, intent(out) :: khit

Integer variables for the coordinates of the BMU

real(kind=wp), intent(out) :: dist_hit

Real variable with the distance to the BMU

public subroutine update_weights(kohonen_map, current_values, ihit, jhit, khit, maximum_radius, iteration)

Subroutine to update the weights

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

real(kind=wp), intent(inout), dimension(:,:) :: current_values

A real array with the values of the current unit

integer, intent(inout) :: ihit

Integer variables with the coordinates of the unit (neuron) to be modified

integer, intent(inout) :: jhit

Integer variables with the coordinates of the unit (neuron) to be modified

integer, intent(inout) :: khit

Integer variables with the coordinates of the unit (neuron) to be modified

real(kind=wp), intent(inout) :: maximum_radius

Real variable with the maximum radius of the neighborhood

integer, intent(inout) :: iteration

Integer variables with the coordinates of the unit (neuron) to be modified

public subroutine calculate_distance_between_prototypes(kohonen_map)

Subroutine to calculate the distance between the prototypes

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

public subroutine find_bmu_grid(kohonen_map, input_data)

Subroutine to calculate the best match unit over the grid

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

type(kohonen_pattern), intent(inout), dimension(:) :: input_data

A kohonen_pattern array with the input data

public subroutine calculate_u_matrix(kohonen_map)

Subroutine to calculate the u_matrix

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

public subroutine calculate_u_matrix_hexagonal(kohonen_map)

Subroutine to calculate the u_matrix for an hexagonal grid

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

public subroutine calculate_u_matrix_rectangular(kohonen_map)

Subroutine to calculate the u_matix for a rectangular grid

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

public subroutine get_u_matrix_som(kohonen_map, u_matrix)

Subroutine to get the u_matrix from a SOM

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

real(kind=wp), intent(out), dimension(:,:,:) :: u_matrix

A real array to return the u_matrix

public subroutine get_prototypes(kohonen_map, prototypes)

Subroutine to get SOM prototypes

Arguments

Type IntentOptional Attributes Name
class(self_organizing_map) :: kohonen_map

A self_organizing_map object

real(kind=wp), intent(out), dimension(:,:) :: prototypes

A real array to return the values of the SOM prototypes

public subroutine external_train_map(x, nvar, npat, nx, ny, nepoch, alpha, grid_type, distance_type, neigh_type, toroidal, prot, distortion, u_matrix, coords, number_patterns, node_index) bind(C, name="train_som")

Subroutine to connect the self_organizing_map module to R o C Import section

Arguments

Type IntentOptional Attributes Name
real(kind=c_double), intent(in) :: x(npat,nvar)

Real array with the input patterns

integer(kind=c_int), intent(in) :: nvar

Integer variables to indicate the number of variables and patterns

integer(kind=c_int), intent(in) :: npat

Integer variables to indicate the number of variables and patterns

integer(kind=c_int), intent(in) :: nx

Integer variables to indicate the number of nodes of the SOM

integer(kind=c_int), intent(in) :: ny

Integer variables to indicate the number of nodes of the SOM

integer(kind=c_int), intent(in) :: nepoch

Integer variables to indicate the number of epochs for training

real(kind=c_double), intent(in) :: alpha

Real value with the initial learning rate

integer(kind=c_int), intent(in) :: grid_type

Integer variable to indicate the type of grid

integer(kind=c_int), intent(in) :: distance_type

Integer variable to indicate the distance type

integer(kind=c_int), intent(in) :: neigh_type

Integer variable to indicate the neighborhood type

integer(kind=c_int), intent(in) :: toroidal

Integer variable to indicate if a toroidal grid is used

real(kind=c_double), intent(out) :: prot(nx*ny,nvar)

Real array for the prototypes

real(kind=c_double), intent(out) :: distortion(nepoch)

Real array for the distortion measure (error during training)

real(kind=c_double), intent(out) :: u_matrix(2*nx-1,2*ny-1)

Real array for the u_matrix

real(kind=c_double), intent(out) :: coords(nx*ny,3)

Real array for the grid coordinates of the SOM

integer(kind=c_int), intent(out) :: number_patterns(nx,ny)

Integer array with the number of hits for each neuron

integer(kind=c_int), intent(out) :: node_index(npat,3)

Integer array with the index node for all the neurons of the SOM

public subroutine external_predict_map(prot, nx, ny, new_pat, npat, nvar, node_index) bind(C, name="predict_som")

Subroutine to connect this module to R

Arguments

Type IntentOptional Attributes Name
real(kind=c_double), intent(in) :: prot(nx*ny,nvar)
integer(kind=c_int), intent(in) :: nx
integer(kind=c_int), intent(in) :: ny
real(kind=c_double), intent(in) :: new_pat(npat,nvar)
integer(kind=c_int), intent(in) :: npat
integer(kind=c_int), intent(in) :: nvar
integer(kind=c_int), intent(out) :: node_index(npat,3)